package com.gold.common;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 统一响应json类
 * @author XiaoHao
 * @date 2022-05-10 11:58
 */
public class JsonUtils {
    public static final int SUCCESS =  200;
    public static final int ERROR =  400;

    public static JSONObject responseJson(boolean success,Integer code,String msg,JSONObject data){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("success",success);
        jsonObject.put("code",code);
        jsonObject.put("message",msg);
        jsonObject.put("data",data);
        return jsonObject;
    }
    public static JSONObject responseJson(boolean success, Integer code, String msg, JSONArray data){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("success",success);
        jsonObject.put("code",code);
        jsonObject.put("message",msg);
        jsonObject.put("data",data);
        return jsonObject;
    }
    public static JSONObject responseJson(boolean success,Integer code,String msg,String data){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("success",success);
        jsonObject.put("code",code);
        jsonObject.put("message",msg);
        jsonObject.put("data",data);
        return jsonObject;
    }
}
